# Filters added to this controller will be run for all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

require 'user_system'

class ApplicationController < ActionController::Base
  include Localization
  include UserSystem

  helper :user
  model :user

  before_filter :login_required
  before_filter :session_expire

  def current_user
    session['user']
  end

  private

  def session_expire
    if session[:user]
      session_length = 60*2 #10 Minutes for logged in users
      expire_time = session[:expire_time] || Time.now + 10
      if expire_time < Time.now
        reset_session
        flash[:notice] = "You have been logged out due to an extended period of inactivity"

        redirect_to :controller => 'welcome' , :action => 'index'
      else
        session[:expire_time] = Time.now + session_length
      end
    end
  end
end